//
//  TKSellerInformationViewController.m
//  Ticket
//
//  Created by 小禹宝宝 on 2017/10/28.
//  Copyright © 2017年 cy55. All rights reserved.
//

#import "TKSellerInformationViewController.h"
#import "BLBaseListViewDataController.h"
#import "TKSellerInformationHeaderView.h"
#import "TKSellerInformationListTableViewCell.h"
#import "TKGoodsListResquest.h"
#import "TKTieziDetailViewController.h"
@interface TKSellerInformationViewController ()
@property (nonatomic, strong) BLBaseListViewDataController *dataSource;
@property (nonatomic, strong) TKSellerInformationHeaderView *topView;

@end

@implementation TKSellerInformationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatTableHeaderView];
    self.navigationItem.title = [NSString stringWithFormat:@"%@的小店",self.user.user_name];
    [self ks_setupLeftBackBarButtonItemWithColor:nil];
    TKGoodsListResquest *request = [TKGoodsListResquest new];
    request.category_id = 0;
    request.sell_user_id = self.user.user_id;
    
    _dataSource = [[BLBaseListViewDataController alloc] initWithRequest:request decodeClass:[TKGoodsListResponse class] afterParseCompletion:^(id responseObject) {
        DDLogInfo(@"responseObject ----:%@",responseObject);
        
        DDLogInfo(@"responseObject ---- list:%@",[(TKGoodsListResponse *)responseObject list]);
    }];
    
    self.listView.pagingListDataSource = _dataSource;
    self.listView.rowHeight = 280;
    [self.listView registerNib:[UINib nibWithNibName:@"TKSellerInformationListTableViewCell" bundle:nil] forCellReuseIdentifier:@"TKSellerInformationListTableViewCell"];
}


- (void)creatTableHeaderView {
    self.topView = [[[NSBundle mainBundle] loadNibNamed:@"TKSellerInformationHeaderView" owner:nil options:nil] firstObject];
    self.topView.model = self.user;
    self.listView.tableHeaderView = self.topView;
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.listView);
        make.height.mas_equalTo(120);
    }];
}


#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.listView.dataItems.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TKSellerInformationListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TKSellerInformationListTableViewCell" forIndexPath:indexPath];
    TKGoodsItem *item = self.listView.dataItems[indexPath.row];
    cell.model = item;
    return cell;
}

#pragma mark - UITableViewDelegate


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    TKGoodsItem *item = self.listView.dataItems[indexPath.row];
    TKTieziDetailViewController *detailVc = [TKTieziDetailViewController new];
    detailVc.goodsID = item.id;
    [KSNavi push:detailVc];
}
@end
